package com.beehoo.dcportal.admin.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.beehoo.dcportal.admin.dao.MessageTypeDao;
import com.beehoo.dcportal.common.base.BaseDao;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.MenuBean;

public class MessageTypeDaoImpl extends BaseDao implements MessageTypeDao {

	private static final Logger logger = Logger
			.getLogger(MessageTypeDaoImpl.class);

	@Override
	public String createMessageType(MenuBean menuBean) throws BaseException {
		String typeId = null;
		try {
			typeId = (String) sqlMapClient.insert(
					"admin-messagetype.createMessageType", menuBean);
			logger.info("信息类型管理-添加信息栏目|#[中心编号：" + menuBean.getStreetId()
					+ "],[信息栏目名称：" + menuBean.getMenuName() + "],成功!");
		} catch (SQLException e) {
			logger.error("信息栏目管理-添加信息栏目|#[中心编号："
					+ menuBean.getStreetId() + "],[信息栏目名称："
					+ menuBean.getMenuName() + "],失败!异常："
					+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.message.type.create.error");
		}
		return typeId;
	}

	@Override
	public int delMessageType(String typeId) throws BaseException {
		int result = 0;
		try {
			result = sqlMapClient.delete("admin-messagetype.delMessageType",
					typeId);
			logger.info("信息栏目管理-删除信息栏目|#[信息栏目编号：" + typeId + "],成功!");
		} catch (SQLException e) {
			logger.error("信息栏目管理-删除信息栏目|#[信息栏目编号： " + typeId + "失败!异常："
					+ e.getMessage());
			throw new BaseException(e, "custom.messages.error.message.type.del.error");
		}
		return result;
	}

	@Override
	public int updateMessageType(MenuBean menuBean) throws BaseException {
		int result = 0;
		try {
			result = sqlMapClient.update("admin-messagetype.updateMessageType",
					menuBean);
			logger.info("信息栏目管理-更新信息栏目|#[信息栏目编号：" + menuBean.getMenuId()
					+ "],[信息栏目名称：" + menuBean.getMenuName() + "],成功!");
		} catch (SQLException e) {
			logger.error("信息栏目管理-更新信息栏目|#[信息栏目编号：" + menuBean.getMenuId()
					+ "],[信息栏目名称：" + menuBean.getMenuName() + "],失败!异常："
					+ e.getMessage());
			throw new BaseException(e, "custom.messages.error.message.type.update.error");
		}
		return result;
	}

	@Override
	public MenuBean queryMessageType(Map<String, Object> paramMap)
			throws BaseException {
		MenuBean bean = null;
		try {
			bean = (MenuBean) sqlMapClient.queryForObject(
					"admin-messagetype.queryMessageType", paramMap);
			logger.info("信息栏目管理-查询信息栏目|#[信息栏目编号：" + paramMap.get("typeId")
					+ "],[中心编号：" + paramMap.get("streetId") + "],成功!");
		} catch (SQLException e) {
			logger.error("信息栏目管理-查询信息栏目|#[信息栏目编号：" + paramMap.get("typeId")
					+ "],[中心编号：" + paramMap.get("typeName") + "],失败!异常："
					+ e.getMessage());
			throw new BaseException(e, "custom.messages.error.message.type.query.error");
		}
		return bean;
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<MenuBean> queryMessageTypeLs(Map<String, Object> paramMap)
			throws BaseException {
		List<MenuBean> ls = null;
		try {
			ls = sqlMapClient.queryForList(
					"admin-messagetype.queryMessageType", paramMap);
			logger.info("信息栏目管理-查询信息栏目|#[信息栏目编号：" + paramMap.get("typeId")
					+ "],[中心编号：" + paramMap.get("streetId") + "],成功!");
		} catch (SQLException e) {
			logger.error("信息栏目管理-查询信息栏目|#[信息栏目编号：" + paramMap.get("typeId")
					+ "],[中心编号：" + paramMap.get("typeName") + "],失败!异常："
					+ e.getMessage());
			throw new BaseException(e, "custom.messages.error.message.type.query.error");
		}
		return ls;
	}

	@Override
	public String initStreetMenu(MenuBean menuBean) throws BaseException {
		String typeId = null;
		try {
			typeId = (String) sqlMapClient.insert(
					"admin-messagetype.initStreetMenu", menuBean);
			logger.info("初始化中心菜单|#[中心编号：" + menuBean.getStreetId()
					+ "],[信息栏目名称：" + menuBean.getMenuName() + "],成功!");
		} catch (SQLException e) {
			logger.error("初始化中心菜单|#[中心编号："
					+ menuBean.getStreetId() + "],[信息栏目名称："
					+ menuBean.getMenuName() + "],失败!异常："
					+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.message.type.create.error");
		}
		return typeId;
	}

	@Override
	public void initStreetMenuPath(Map<String, Object> paramMap)
			throws BaseException {
		try {
			sqlMapClient.update("admin-messagetype.initStreetMenuPath", paramMap);
			logger.info("初始化中心菜单路径|#[菜单编号：" + paramMap.get("menuId")
					+ "],[菜单路径：" + paramMap.get("menuPath") + "],成功!");
		} catch (SQLException e) {
			logger.error("初始化中心菜单路径|#[菜单编号：" + paramMap.get("menuId") 
					+ "],[菜单路径：" + paramMap.get("menuPath") + "],失败!异常："
					+ e.getMessage());
			throw new BaseException(e,
					"custom.messages.error.message.type.create.error");
		}
		
	}

}
